{% extends "admin/base.html" %}
{% block title %}-成绩管理{% endblock %}
{% block grade %}current-item{% endblock %}
{% block mainbody %}

        <div class="main">
			<center>
				<h1>添加用户</h1>
				<span id="error" class="error">{{ error }}</span>
				<form id="insert-form" method="post" action="/admin/insertuser">
					<table class="table-adduser">
						<tr>
							<td>
								<span>user_name:</span>
							</td>
							<th>
								<input type="text" name="user_name">
							</th>
						</tr>
						<tr>
							<td>
								<span>user_sex:</span>
							</td>
							<th>
								<input type="text" name="user_sex">
							</th>
						</tr>
						<tr>
							<td>
								<span>user_age:</span>
							</td>
							<th>
								<input type="text" name="user_age">
							</th>
						</tr>
						<tr>
							<td>
								<span>user_phone:</span>
							</td>
							<th>
								<input type="text" id="user_phone" name="user_phone">
								<span class="error">*</span>
							</th>
						</tr>
						<tr>
							<td>
								<span>user_nick:</span>
							</td>
							<th>
								<input type="text" name="user_nick">
							</th>
						</tr>
						<tr>
							<td>
								<span>user_pwd:</span>
							</td>
							<th>
								<input type="password" id="user_pwd" name="user_pwd">
								<span class="error">*</span>
							</th>
						</tr>
{#						<tr>#}
{#							<td>#}
{#								<span>is_admin:</span>#}
{#							</td>#}
{#							<th>#}
{#								<input type="text" id="isadmin" name="username">#}
{#							</th>#}
{#						</tr>#}
					</table>
					<input type="button" id="submit_btn" value="提交">
				</form>

			</center>
		</div>

		<script src="/public/js/common/jquery-1.12.4.min.js"></script>
		<script>
			$(document).keydown(function(event) {
				if(event.keyCode == 13) {
					submitForm()
				}
			});

			$("#submit_btn").click(function() {
				submitForm()
			})

            function  submitForm() {
                if (checkForm()) {
                    $("#error").html("正在提交...");
                    $("#insert-form").submit();
                }
            }

            function checkForm() {
                console.log($("#user_phone").val())
                $("#error").html("");
                if($("#user_phone").val().trim() == '') {
					$("#error").html("请输入phone");
                    return false;
				}
				if($("#user_pwd").val().trim() == '') {
					$("#error").html("请输入pwd");
                    return false;
				}
				return true;
            }

			$("#user_phone").blur(function() {
				checkForm()
			})

			$("#user_pwd").blur(function() {
				checkForm()
			})

		</script>
{% endblock %}